﻿// This source is subject to Microsoft Public License (Ms-PL).
// Please see http://taskcardcreator.codeplex.com for details.
// All other rights reserved.

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using WorkItemReportInterface;

namespace TaskCardCreator
{
  /// <summary>
  /// Interaction logic for ReportSelectPopup.xaml
  /// </summary>
  public partial class ReportSelectPopup : Window
  {
    private List<IWorkItemReport> localReportList = new List<IWorkItemReport>();

    public IWorkItemReport SelectedReport;

    public ReportSelectPopup(IEnumerable<IWorkItemReport> reports)
    {
      InitializeComponent();

      foreach (var report in reports)
      {
        reportListBox.Items.Add(report.Description);
        localReportList.Add(report);
      }
      reportListBox.SelectedIndex = 0;
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
      var selectedItem = reportListBox.SelectedItem;

      SelectedReport = (from r in localReportList
                        where r.Description == selectedItem
                        select r).FirstOrDefault();
      
      DialogResult = true;
      Close();
    }

    private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
    {
      System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri));
      e.Handled = true;
    }
  }
}